import request from "@/utils/request"
import { setChannelList, setArticleList } from '../modules/article'

/**
 * 获取文章频道列表
 * @param {*} payload 
 * @returns 
 */
export const getChannelAction = (payload) => {
  return async (dispatch, getState) => {
    // 1. 获取后台频道数据
    const { data } = await request.get('/channels')
    console.log('频道数据：', data.data.channels)
    // 2. 存储频道数据到redux
    dispatch(setChannelList(data.data.channels))
  }
}

export const getArticleAction = (params) => {
  return async (dispatch, getState) => {
    const { data } = await request.get('/mp/articles', {
      params
    })
    console.log('文章列表：', data.data)
    dispatch(setArticleList(data.data))
  }
}